package thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class TimerUse {
//    List<String> list = Arrays.asList("a","b","c");
    ArrayList<String> list = new ArrayList<String>(Arrays.asList("a","b","c"));
    public void test() throws ParseException {
        Timer timer = new Timer();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        Date firstTime = sdf.parse("2019-4-19 19:09:00");
        timer.schedule(new TimerTask() {
                           @Override
                           public void run() {
                               for (int i = 0; i < list.size(); i++){
                                   System.out.println(list.get(i));
                               }
                               System.out.println("结束");
                           }
                       }
                , firstTime, 3000
        );

    }

    public static void main(String[] args) {
        TimerUse use = new TimerUse();
        try {
            use.test();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

}
